<?php
session_start();
require_once("../include/db.php");
require_once("../xajax_core/xajax.inc.php");
$xajax = new xajax("member.common.php");
$xajax->registerFunction("uwannamail");
$xajax->registerFunction("unwannamail");
$xajax->configure('javascript URI', '../');

function uwannamail($mailingid)
{
    $objResponse = new xajaxResponse();
    $memberid=$_SESSION["memberid"];
    $sql = "insert into membermailing(mailingid,memberid) values($mailingid,$memberid)";
    $conn=getconnection();
    $result = mysql_query($sql, $conn);
    
    $sqlabc ="update company set checkedcount=checkedcount+1 where id in (select companyid from mailing where id=$mailingid)";
    $tttt = mysql_query($sqlabc, $conn);
    
    /*
    $err = mysql_error(); 
    if($err)
    {
 	     $objResponse->alert("uwannamail fail ".$err);
    }
    else
    {
     	 $objResponse->alert("uwannamail success.");
    }
    */
 	 $objResponse->assign("submit","disabled",false);
   return $objResponse;
};
function unwannamail($mailingid)
{
    $objResponse = new xajaxResponse();
    $memberid=$_SESSION["memberid"];
    $sql = "delete from membermailing where mailingid=$mailingid and memberid=$memberid";
    
    $conn=getconnection();
    $result = mysql_query($sql, $conn);
    $sqlabc ="update company set checkedcount=checkedcount-1 where id in (select companyid from mailing where id=$mailingid)";
    $tttt = mysql_query($sqlabc, $conn);
    
    /*
    $err = mysql_error(); 
    if($err)
    {
 	     $objResponse->alert("unwannamail fail ".$err);
    }
    else
    {
     	 $objResponse->alert("unwannamail success.");
    }
    */
 	  $objResponse->assign("submit","disabled",false);
    return $objResponse;
};
$xajax->processRequest();
?>
